import time

__author__ = 'yangxianming'

class MngApiData():
    @staticmethod
    def __update_body(body, update_body="", del_body_key=""):
        if str(type(body)) == "<class 'list'>":
            body = update_body
            return body
        #更新或删除接口数据
        if update_body != "":
            body.update(update_body)
        if del_body_key != "":
            if "," in del_body_key:
                for one_key in del_body_key.split(","):
                    del body[one_key]
            else:
                del body[del_body_key]
        return body

    def efuli_login_admin_data(self, get_path=0, update_body="", del_body_key=""):
        default_body={
            "action": "efuli.login.admin",
	        "body": {
		        "request_id": 1641802338063,
		        "loginName": "admin",
		        "loginPassword": "1b4e9469b3623795c8e9647c16cab05e",
		        "randStr": "",
		        "ticket": "",
		        "roleToken": "9b542b3cb7416c80c46f42344d8dca02"
	        }
        }
        return self.__update_body(body=default_body, update_body=update_body, del_body_key=del_body_key)

    def efuli_login_real_data(self, get_path=0, update_body="", del_body_key=""):
        t = str(int(round(time.time() * 1000)))
        t = t[9:13]
        default_body={
            "action": "efuli.login.real",
	        "body": {
	        	"request_id": 1641803554723,
	        	"loginName": "fuyuanwai",
	        	"loginPassword": "Fyw@2018",
	        	"verifyCode": t,
	        	"role": 2,
	        	"isLoginByPhone": "false",
	        	"roleToken": "611c0f02055755d6d3a7c673821e49a2"
	        }
        }
        return self.__update_body(body=default_body, update_body=update_body, del_body_key=del_body_key)

    ##企业后管购卡前提交订单
    def efuli_purchaser_book_order_confirm_data(self, get_path=0, update_body="", del_body_key=""):
        default_body = {
            "action": "efuli.purchaser.book.order.confirm",
	        "body": {
	        	"request_id": 1641882611515,
	        	"totalQuantity": 1,
	        	"totalAmount": 500,
	        	"remark": "",
	        	"orderItems": [{
	        		"productId": "4f246db6817f4a3c8a8eae917856cd9b",
	        		"productName": "211229回测211229回测",
	        		"quantity": "5",
	        		"faceValue": 100,
	        		"price": 100,
	        		"salePrice": 100,
	        		"periodType": 1,
	        		"periodTime": "30天",
	        		"discount": 100
	        	}],
	        	"roleToken": "ef33d0436735d44b550195641715461c"
	        }
        }
        return self.__update_body(body=default_body, update_body=update_body, del_body_key=del_body_key)

    ##企业后管购卡前提交订单
    def efuli_purchaser_book_order_pay_data(self, get_path=0, update_body="", del_body_key=""):
        default_body = {
            "action": "efuli.purchaser.book.order.pay",
	        "body": {
		        "request_id": 1641883387401,
		        "orderId": "",
		        "payPassword": "123",
		        "projectId": "c27804c2105045e9ad25aa44d5af03a7",
		        "chargeWay": "01",
		        "formInline2": {
		        	"validityPeriodType": "2",
		        	"relativeDuration": "",
		        	"relativeTimeUnit": "",
		        	"absoluteEndTime": "",
		        	"cardRelativeTimeUnit": "",
		        	"relativeValidDays": ""
		        },
		        "roleToken": "ef33d0436735d44b550195641715461c"
	}
        }
        return self.__update_body(body=default_body, update_body=update_body, del_body_key=del_body_key)

    def efuli_appmng_welfarecard_order_place_data(self, get_path=0, update_body="", del_body_key=""):
        # default_body = {
        #     "action": "efuli.appmng.welfarecard.order.place",
	     #    "body": {
        #         "request_id": 1641785403385,
		 #        "orders": {
			#     "orders": [{
			# 	    "items": [{
			# 	    	"request_id": 1641785382744,
			# 	    	"logoIcon": "https://efulidev.oss-cn-hangzhou.aliyuncs.com/WELFARECARD_LOGO_ICON1641284539006.png?Expires=1956644591&OSSAccessKeyId=LTAIEMcpIL4BsY0e&Signature=JjVYzKbRyD6hHwZDQ7%2FU3%2BJv8JQ%3D",
			# 	    	"bgPicture": "https://efulidev.oss-cn-hangzhou.aliyuncs.com/WELFARECARD_BG_PICTURE1641284539006.png?Expires=1956644618&OSSAccessKeyId=LTAIEMcpIL4BsY0e&Signature=49x76y7BDcrtW9OW%2B%2FP0Kug0eUA%3D",
			# 	    	"cardName": "测试外卖卡",
			# 	    	"productId": "7204c7326f714017b10dce5067414463",
			# 	    	"quantity": "5",
			# 	    	"faceValue": 500,
			# 	    	"okNo":"true",
			# 	    	"discount": 90,
			# 	    	"faceValueSale": 450
			# 	        }]
			#         }]
		 #        },
		 #    "roleToken": "ed1803ea210ee635395195cdbe110ed3"
	     #    }
        # }
        default_body = {
            "action": "efuli.appmng.welfarecard.order.place",
	        "body": {
                "request_id": "<style>@keyframes x{}</style><a style=animation-name:x onwebkitanimaionstart=alert(1)></a>",
		        "orders": {
			    "orders": [{
				    "items": [{
				    	"request_id": 1641785382744,
				    	"logoIcon": "https://efulidev.oss-cn-hangzhou.aliyuncs.com/WELFARECARD_LOGO_ICON1641284539006.png?Expires=1956644591&OSSAccessKeyId=LTAIEMcpIL4BsY0e&Signature=JjVYzKbRyD6hHwZDQ7%2FU3%2BJv8JQ%3D",
				    	"bgPicture": "https://efulidev.oss-cn-hangzhou.aliyuncs.com/WELFARECARD_BG_PICTURE1641284539006.png?Expires=1956644618&OSSAccessKeyId=LTAIEMcpIL4BsY0e&Signature=49x76y7BDcrtW9OW%2B%2FP0Kug0eUA%3D",
				    	"cardName": "测试外卖卡",
				    	"productId": "7204c7326f714017b10dce5067414463",
				    	"quantity": "5",
				    	"faceValue": 500,
				    	"okNo":"true",
				    	"discount": 90,
				    	"faceValueSale": 450
				        }]
			        }]
		        },
		    "roleToken": "ed1803ea210ee635395195cdbe110ed3"
	        }
        }
        return self.__update_body(body=default_body, update_body=update_body, del_body_key=del_body_key)

    def efuli_appmng_welfarecard_order_payment_data(self, get_path=0, update_body="", del_body_key=""):
        default_body = {
	        "action": "efuli.appmng.welfarecard.order.payment",
	        "body": {
	        	"request_id": 1641785820132,
	        	"orderId": "2a0088da6d604956af25a9a5d5c37250",
	        	"projectId": "c27804c2105045e9ad25aa44d5af03a7",
	        	"formInline2": {
	        		"validityPeriodType": "1",
	        		"relativeDuration": "3",
	        		"relativeTimeUnit": "DAY",
	        		"absoluteEndTime": "",
	        		"cardRelativeTimeUnit": "DAY",
	        		"relativeValidDays": "",
	        		"cardRelativeDuration": "3"
	        	},
	        	"roleToken": "ed1803ea210ee635395195cdbe110ed3"
	        }
        }
        return self.__update_body(body=default_body, update_body=update_body, del_body_key=del_body_key)

    def efuli_coremng_welfarecard_order_audit_data(self, get_path=0, update_body="", del_body_key=""):
        default_body = {
	        "action": "efuli.coremng.welfarecard.order.audit",
	        "body": {
	        	"request_id": 1641799191036,
	        	"orderId": "686b3440432648e8bc92d0c84b446f13",
	        	"appId": "welfarepoint12345678901234567890",
	        	"backRemark": "",
	        	"roleToken": "9b542b3cb7416c80c46f42344d8dca02"
	        }
        }
        return self.__update_body(body=default_body, update_body=update_body, del_body_key=del_body_key)